import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { CustomerFollowEntity } from '../../entity/follow';
import { CustomerFollowService } from '../../service/follow';
import { BaseSysUserEntity } from '../../../base/entity/sys/user';

/**
 * 客户跟进
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: CustomerFollowEntity,
  service: CustomerFollowService,
  pageQueryOp: {
    fieldEq: ['a.type'],
    keyWordLikeFields: [],
    where: async ctx => {
      const { startTime, endTime } = ctx.request.body;
      const where = [];
      if (startTime && endTime) {
        where.push([
          'a.time >= :startTime AND a.time <= :endTime',
          { startTime, endTime },
        ]);
      }
      return where;
    },
    join: [
      {
        entity: BaseSysUserEntity,
        alias: 'b',
        condition: 'a.userId = b.id',
        type: 'leftJoin',
      },
    ],
    select: ['a.*', 'b.nickName as userName'],
  },
})
export class AdminCustomerFollowController extends BaseController {
  @Inject()
  customerFollowService: CustomerFollowService;
}
